package com.kylin.shared.enums;

import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.util.CollectionUtils;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.stream.Collectors;

/**
 * 拼团状态
 * @author Damon S.
 * @version v1.0.1
 * @date 2019年11月22日 15:34
 */
@Getter
@RequiredArgsConstructor
public enum GrouponState {
    /**活动状态，0NA，1待成团，2已成团，3团购失效，4手动暂停，5手动结束 */
    NA(0),
    DRAFTING(1),
    PUBLISHED(2),
    FINISHED(3),
    PAUSED(4),
    STOPPED(5);

    private final int code;

    public static GrouponState parse(Integer code) {
        List<GrouponState> filteredStates =
                Arrays.stream(GrouponState.values())
                        .filter(state -> Objects.equals(state.getCode(), code))
                        .collect(Collectors.toList());
        return CollectionUtils.isEmpty(filteredStates) ? NA : filteredStates.get(0);
    }
}
